<html>
<head><meta charset="utf-8"><title>generic argument disambiguation #2 · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html">generic argument disambiguation #2</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="213086660"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213086660" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213086660">(Oct 12 2020 at 21:07)</a>:</h4>
<p>I'd like to gather thoughts regarding a different solution to disambiguating generic arguments in expressions without the <code>::&lt;</code> sigil. Though I'd personally still be in favour of simply disambiguating in favour of generic arguments, and losing LL(k), this has obviously caused some contention in the past: if we could avoid this, while removing the syntax papercut, that would be a win. As far as I can tell, there <em>is</em> another approach that addresses both the undesirable <code>::</code> and retains LL(k) parsing. (Of course, it has some downsides of its own, but I feel these are outweighed by the benefits.) It could well be this was suggested in the past, though I wasn't able to find record of it. I believe it's become more viable recently, though.</p>



<a name="213086938"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213086938" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213086938">(Oct 12 2020 at 21:10)</a>:</h4>
<p>The idea is to differentiate <code>a &lt;</code> and <code>a&lt;</code> as a comparison, and const arguments, respectively. That is: generic arguments and comparisons are disambiguated by leading whitespace.<br>
There are several considerations here:</p>
<ul>
<li>Readability is likely the main one. There are two aspects: if someone deliberately formats their code without whitespace, and if someone accidentally forgets to include whitespace. I should hope that the former case is relatively rare (especially with rustfmt gaining widespread use), though the latter is very reasonable. However, as has been discussed previously with regards to this topic, the situation where an expression can successfully parse as both a comparison and a generic argument is extremely rare (there are two synthetic examples, but I don't see these happening in practice for reasons I can elaborate on). This means a missing/extra space would be an error in almost all cases, allowing us to emit custom diagnostics, which will make the problem very clear to the user.</li>
<li>Rust prefers to be whitespace agnostic. This is true to a large extent, but it is not always the case. There are <a href="#narrow/stream/213817-t-lang/topic/whitespace.20sensitivity.20with.20symbols/near/212930494">several situations</a> where whitespace vs no whitespace lead to different (valid) parses. In theory, we would be treating <code>IDENT&lt;</code> as a single token. It's fair to say this case of whitespace-sensitivity would be more commonly encountered than the existing ones, but I think this would still be relatively rare in practice.</li>
<li>This approach is unambiguous and keeps Rust's finite lookahead, which was/is the main point of contention with the previous proposal.</li>
<li>We could rustfix existing incorrect formatting for a new edition, so there aren't any issues with compatibility. Making this change along with a new edition seems plausible.</li>
</ul>



<a name="213087075"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087075" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087075">(Oct 12 2020 at 21:12)</a>:</h4>
<p>At first, I was skeptical about introducing an extra whitespace-sensitive situation, but the more I've thought about it, the more the idea has grown on me. I think in practice, users are unlikely to notice this special-case, and everything will work as expected.</p>



<a name="213087134"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087134" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087134">(Oct 12 2020 at 21:13)</a>:</h4>
<p>I think Zulip allows for more thought out conversations than GH, so hopefully this is an appropriate place to have such a discussion. I'm particularly interested to hear what the lang team thinks, considering the discussions we've had in the past re. generic argument disambiguation.<br>
cc <span class="user-group-mention" data-user-group-id="1977">@T-lang</span></p>



<a name="213087218"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087218" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087218">(Oct 12 2020 at 21:14)</a>:</h4>
<p>Now does seem like the right time to have this discussion, if we're to have it at all, because making such a change would likely be edition-sensitive.</p>



<a name="213087421"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087421" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087421">(Oct 12 2020 at 21:17)</a>:</h4>
<p>This is an interesting point.</p>



<a name="213087429"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087429" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087429">(Oct 12 2020 at 21:17)</a>:</h4>
<p>I hadn't considered the edition angle here.</p>



<a name="213087514"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087514" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087514">(Oct 12 2020 at 21:18)</a>:</h4>
<p>This is an issue that I don't generally feel like i have the "spoons", as <span class="user-mention" data-user-id="239881">@Josh Triplett</span> likes to say, to want to pursue right now. But this is an interesting compromise that might be appealing to folks.</p>



<a name="213087533"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087533" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087533">(Oct 12 2020 at 21:18)</a>:</h4>
<p>I guess I have to read the details of where else we consider whitespace as important</p>



<a name="213087544"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087544" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087544">(Oct 12 2020 at 21:19)</a>:</h4>
<p>The main arguments I can see against have to do with the ease of writing code that generates rust code etc</p>



<a name="213087566"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087566" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087566">(Oct 12 2020 at 21:19)</a>:</h4>
<p>I personally don't feel it's as ideal as just accepting the lookahead (considering that we'd want to do lookahead parsing for error handling and error correction anyway). But both are better than turbofish.</p>



<a name="213087573"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087573" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087573">(Oct 12 2020 at 21:19)</a>:</h4>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232/near/213087075">said</a>:</p>
<blockquote>
<p>At first, I was skeptical about introducing an extra whitespace-sensitive situation, but the more I've thought about it, the more the idea has grown on me. I think in practice, users are unlikely to notice this special-case, and everything will work as expected.</p>
</blockquote>
<p>An important point here would probalby be our ability to issue nice errors. It seems quite likely we could do so.</p>



<a name="213087918"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087918" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087918">(Oct 12 2020 at 21:24)</a>:</h4>
<p>It felt like, last time, we just stalled out due to objections to lookahead.</p>



<a name="213087979"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213087979" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213087979">(Oct 12 2020 at 21:24)</a>:</h4>
<p>This approach seems unlikely to hit the <em>same</em> objection.</p>



<a name="213088006"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213088006" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213088006">(Oct 12 2020 at 21:24)</a>:</h4>
<p>I still feel like choosing this path due to that objection would be dodging the "why" question on that objection.</p>



<a name="213088772"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213088772" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213088772">(Oct 12 2020 at 21:35)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232/near/213087573">said</a>:</p>
<blockquote>
<p><span class="user-mention silent" data-user-id="121053">varkor</span> <a href="#narrow/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232/near/213087075">said</a>:</p>
<blockquote>
<p>At first, I was skeptical about introducing an extra whitespace-sensitive situation, but the more I've thought about it, the more the idea has grown on me. I think in practice, users are unlikely to notice this special-case, and everything will work as expected.</p>
</blockquote>
<p>An important point here would probalby be our ability to issue nice errors. It seems quite likely we could do so.</p>
</blockquote>
<p>Yes, I think our ability to emit nice errors in this case would be essentially the same as for the infinite lookahead version (which works pretty well with a little effort).</p>



<a name="213088908"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213088908" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213088908">(Oct 12 2020 at 21:37)</a>:</h4>
<p><span class="user-mention silent" data-user-id="239881">Josh Triplett</span> <a href="#narrow/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232/near/213088006">said</a>:</p>
<blockquote>
<p>I still feel like choosing this path due to that objection would be dodging the "why" question on that objection.</p>
</blockquote>
<p>Perhaps. But if this approach is generally more favourable anyway, then perhaps it doesn't matter if we leave the "why" unanswered.</p>



<a name="213089064"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213089064" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213089064">(Oct 12 2020 at 21:39)</a>:</h4>
<p><span class="user-mention silent" data-user-id="116009">nikomatsakis</span> <a href="#narrow/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232/near/213087514">said</a>:</p>
<blockquote>
<p>This is an issue that I don't generally feel like i have the "spoons", as <span class="user-mention silent" data-user-id="239881">Josh Triplett</span> likes to say, to want to pursue right now. But this is an interesting compromise that might be appealing to folks.</p>
</blockquote>
<p>If there's a feeling that this could be worth investigating for the next edition, I would be willing to put time into exploring the potential concerns. I know not everyone feels an edition is necessary for addressing <code>::</code>, but if it can be aligned with an edition change, that certainly seems most convenient.</p>



<a name="213090904"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213090904" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213090904">(Oct 12 2020 at 22:06)</a>:</h4>
<p>I'm game, personally. Can I suggest informally polling a few more <span class="user-group-mention" data-user-group-id="1977">@T-lang</span> members to see if they'd be generally favorable, before putting in too much effort?</p>



<a name="213091027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213091027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213091027">(Oct 12 2020 at 22:08)</a>:</h4>
<p>I'd definitely like to hear what others think. I guess at the end of the day this issue has never seemed terribly high priority to me, I have to admit, so I worry about opening this door, but I am interested in this as a possible solution.</p>



<a name="213091314"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213091314" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213091314">(Oct 12 2020 at 22:12)</a>:</h4>
<p>I'll send them a message if I don't hear anything in a little while.</p>



<a name="213093914"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213093914" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> scottmcm <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213093914">(Oct 12 2020 at 22:50)</a>:</h4>
<p>With all the conversations about breakage in macro_rules (see <code>n#</code> vs <code>r#</code>) I sometimes wish we were stricter about requiring spaces between things.  That said, I'll need to think more about how I feel about requiring that there <em>not</em> be a space in a certain place that, TBH, I've never thought of as a single token.</p>
<p>I guess my initial worry here is that this is just trading the "lookahead!" land mine for a "whitespace!" land mine, and a whole bunch of "I don't want Rust to have python-like whitepace".  (Not that this proposal would get anywhere close to python's, but I still expect the comments to show up.)</p>



<a name="213096015"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213096015" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> varkor <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213096015">(Oct 12 2020 at 23:28)</a>:</h4>
<p>Yeah, I know what you mean. It may be worth noting that other languages (e.g. C#, Swift, etc.) have stricter policies about whitespace than Rust does, whilst still being fairly whitespace-agnostic (and I haven't heard complaints about whitespace in those languages).</p>



<a name="213159746"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213159746" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213159746">(Oct 13 2020 at 14:10)</a>:</h4>
<p>I think <code>a&lt;x</code> as a comparison is not so uncommon, especially in code that gets a bit golfy like <code>filter(|x| x&lt;y)</code> when you are trying to fit within a line limit</p>



<a name="213159877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213159877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213159877">(Oct 13 2020 at 14:11)</a>:</h4>
<p>I don't think being whitespace sensitive here is a very good idea, if we're going to pursue this I'd much rather use lookahead.</p>



<a name="213160060"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213160060" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213160060">(Oct 13 2020 at 14:12)</a>:</h4>
<p>Also, I think there's a distinct difference between being whitespace sensitive between two distinct tokens (an ident and a lt) vs being whitespace sensitive because sequences of punctuation are lexed as one token or two</p>



<a name="213202282"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213202282" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213202282">(Oct 13 2020 at 19:01)</a>:</h4>
<p>I don't quite get the distinction you're drawing at the end there, <span class="user-mention" data-user-id="256759">@boats</span></p>



<a name="213228747"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213228747" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213228747">(Oct 13 2020 at 23:09)</a>:</h4>
<p>I think I might...</p>



<a name="213228833"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213228833" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213228833">(Oct 13 2020 at 23:10)</a>:</h4>
<p><span class="user-mention" data-user-id="256759">@boats</span> You're saying you see it as much more acceptable to lex a series of punctuation differently depending on if it has whitespace separation or not, than it is to care whether there's whitespace between punctuation and another token?</p>



<a name="213228985"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213228985" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213228985">(Oct 13 2020 at 23:12)</a>:</h4>
<p>For instance, lexing <code>///</code> (doc-comment) differently from <code>/ //</code> (divide then comment), as compared to lexing <code>x/y</code> differently from <code>x / y</code>?</p>



<a name="213228992"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213228992" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213228992">(Oct 13 2020 at 23:12)</a>:</h4>
<p>That seems reasonable to me as well.</p>



<a name="213229010"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213229010" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Josh Triplett <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213229010">(Oct 13 2020 at 23:12)</a>:</h4>
<p>I would rather use lookahead as well, personally.</p>



<a name="213306799"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213306799" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> boats <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213306799">(Oct 14 2020 at 15:28)</a>:</h4>
<p>yea, exactly what Josh says</p>



<a name="213648995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/generic%20argument%20disambiguation%20%232/near/213648995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Vadim Petrochenkov <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/generic.20argument.20disambiguation.20.232.html#213648995">(Oct 17 2020 at 12:08)</a>:</h4>
<p>I'd suggest to try solving this by introducing a cover grammar that accepts both types and expressions (and possibly patterns as well).<br>
It's a more widely applicable idea than a single white-space sensitive parsing exception, it can be used to disambiguate not only most of turbofishes, but e.g. type vs const generic arguments as well (<a href="https://github.com/rust-lang/rust/issues/77773">#77773</a> on steroids, basically), as well as improve diagnostics.</p>
<p>In pseudocode:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="k">fn</span> <span class="nf">parse_expr_or_type</span><span class="p">()</span><span class="w"> </span>-&gt; <span class="nc">ExprOrType</span><span class="w"> </span><span class="p">{</span><span class="w"> </span><span class="o">..</span><span class="p">.</span><span class="w"> </span><span class="p">}</span><span class="w"></span>

<span class="k">enum</span> <span class="nc">ExprOrType</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="n">Expr</span><span class="p">(</span><span class="n">ExprKind</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="n">Type</span><span class="p">(</span><span class="n">TypeKind</span><span class="p">),</span><span class="w"></span>
<span class="w">    </span><span class="n">Ambiguous</span><span class="p">(</span><span class="n">ExprOrTypeLetResolveDecide</span><span class="p">),</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>It's a pretty significant experimental endeavor though, someone needs to actually try and implement such parsing, and find out whether it's possible to do it with a finite lookahead, and estimate how hard would it make the compiler writer's life to not know whether something is a type or expression until resolve/HIR-lowering.</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>